package mylibrary.xml.demo.suit;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class GenericKeyInfo {

	protected Element keyInfo = null;
	
	protected Document doc = null;
	
	protected boolean elementAppendedToDoc = false;
	
	public GenericKeyInfo(Document document, String nsQlif, int typeNo) {
		
		doc = document;
		keyInfo = doc.createElement(nsQlif + ":KeyInfo");
		
		keyInfo.setAttribute("xmlns:" + nsQlif, AlgoNames.getAlgoNSValue(typeNo));
		
	}
	
	public void setKeyName(String keyName) {
		Element tempElem = doc.createElement("KeyName");
		tempElem.appendChild(doc.createTextNode(keyName));
		keyInfo.appendChild(tempElem);
	}
	
	public void setKeyValue(String keyValue) {
		Element tempElem = doc.createElement("KeyValue");
		tempElem.appendChild(doc.createTextNode(keyValue));
		keyInfo.appendChild(tempElem);
	}
	
	public void setRetrievalMethod(String uriValue, int typeNo) {
		Element tempElem = doc.createElement("RetrievalMethod");
		tempElem.setAttribute("URI", uriValue);
		tempElem.setAttribute("Type", AlgoNames.getAlgoNSValue(typeNo));
		keyInfo.appendChild(tempElem);
	}
	
	public Document getKeyInfo() {
		if(elementAppendedToDoc == false) {
			doc.appendChild(keyInfo);
			elementAppendedToDoc = true;
		}
		return doc;
	}
}
